package util.dbutil;

import bean.Room;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import util.C3p0Util;

import java.sql.SQLException;
/**
 * 房间管理菜单工具类
 * */
public class LoginRoom {


    /*
    房间录入
    */
    public int insertRoom(Room room){
        int count = 0;
        QueryRunner runner = new QueryRunner(C3p0Util.getDs());
        String sql = "insert into t_room (r_id,r_number,r_sex,r_innumber,r_money) values (?,?,?,?,?)";

        try {
            /*
                - update DML 针对增、删、改的语句都可以使用
                    参数1：sql
                    参数2：可变数组，存放的是占位符对应的数据值
             */
            count = runner.update(sql,room.getId(),room.getrNumber(),room.getSex(),room.getInNumber(),room.getMoney());
            if(count > 0){
                System.out.println("执行成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return count;
    }


    /*
    房间修改
     */
    public int updateRoom(Room room){
        int count = 0;
        QueryRunner runner = new QueryRunner(C3p0Util.getDs());
        String sql = "update t_room set r_sex=?,r_innumber=?,r_money=? where r_number=?";

        try {
            /*
                - update DML 针对增、删、改的语句都可以使用
                    参数1：sql
                    参数2：可变数组，存放的是占位符对应的数据值
             */
            count = runner.update(sql,room.getSex(),room.getInNumber(),room.getMoney(),room.getrNumber());
            if(count > 0){
                System.out.println("执行成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return count;
    }
}
